word_to_num = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
words = input().split()
if len(words) != 3:
    print("wrong input")
else:
    num_str = ""
    for word in words:
        if word in word_to_num:
            num_str += str(word_to_num[word])
        else:
            print("wrong input")
            break
    else:
        if len(num_str) != 3:
            print("wrong input")
        else:
            num = int(num_str)
            count = 0
            while True:
                if is_prime(num + count):
                    print(num + count)
                    break
                elif is_prime(num - count) and num - count > 1:
                    print(num - count)
                    break
                count += 1
